<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>素材库管理</el-breadcrumb-item>
      <el-breadcrumb-item>素材商城</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <div class="materialMall">素材商城</div>
      <div class="materialType">
        素材类别
        <el-select v-model="value" clearable placeholder="--请选择--" class="materialSelect">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-select v-model="value1" clearable placeholder="--请选择--" class="materialSelect">
          <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <span class="note">注：由于本商城产品属于虚拟产品，一经购买，不提供退款服务</span>
      </div>
      <el-input placeholder="输入想要搜索的素材名称" v-model="search" class="input-with-select">
        <el-button @click="handle" slot="append">搜索</el-button>
      </el-input>
      <div class="materialShop">
        <div class="material_shop" v-for="(item,index) in listMaterial" :key="index">
          <div class="picture">
            <img
              src="https://www.splitshire.com/wp-content/uploads/2016/02/SplitShire-2851.jpg"
              alt
            />
          </div>
          <span>{{item.material_name}}</span>
          <p>{{item.uploader}}</p>
          <p>{{item.vegetable}}</p>
          <div class="buyMaterial">
            <span>{{item.price}}</span>
            <span class="buyMaterialState">{{item.templateState}}</span>
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import '@/mock/yyzmock.js'
export default {
  name: '',
  components: {},
  props: {},
  data () {
    return {
      options: [{
        value: '选项1',
        label: '类别1'
      }, {
        value: '选项2',
        label: '类别2'
      },
      {
        value: '选项3',
        label: '........'
      }],
      options1: [{
        value: 'xuanxiang1',
        label: '子类别1'
      }, {
        value: 'xuanxiang2',
        label: '子类别2'
      },
      {
        value: 'xuanxiang3',
        label: '........'
      }],
      value: '',
      value1: '',
      search: '',
      listMaterial: [],
      searchList: []
    }
  },
  computed: {},
  watch: {},
  created () {
    this.requestMock()
  },
  mounted () {

  },
  methods: {
    async requestMock () {
      const { data } = await this.axios.get('/materialMall')
      this.listMaterial = data.data
      this.searchList = data.data
    },
    handle () {
      if (this.search !== '') {
        this.listMaterial = this.listMaterial.filter(item => item.material_name === this.search)
      } else {
        this.listMaterial = this.searchList
      }
    }
  }
}
</script>

<style scoped lang="less">
.el-card {
  .materialType {
    display: inline-block;
    margin-top: 40px;
    width: 100%;
  }
  .materialSelect {
    margin-left: 10px;
  }
  .note {
    float: right;
    color: #e97d79;
    font-size: 13px;
    height: 20px;
    line-height: 40px;
  }
  .input-with-select {
    width: 474px;
    margin-top: 20px;
  }
  .materialShop {
    display: flex;
    flex-wrap: wrap;
    margin-top: 40px;
    .material_shop {
      width: 20%;
      .picture img {
        border: 10px solid #ccc;
        width: 150px;
        height: 120px;
      }
      span,
      p {
        font-size: 13px;
      }
      .buyMaterial {
        width: 170px;
        display: flex;
        justify-content: space-between;
        margin-bottom: 10px;
      }
    }
  }
}
</style>
